package logic

import (
	"context"
	"go.uber.org/zap"
	"smart-health-platforms/pkg"
	"user_srv/internal/svc"
	"user_srv/model"

	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectListLogic {
	return &CollectListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品列表
func (l *CollectListLogic) CollectList(in *user.CollectListRequest) (*user.CollectListResponse, error) {
	var coll model.Collection
	coll.UserId = int32(in.UserId)
	list, _, err := coll.GetCollectionList(int(in.Page), int(in.PageSize))
	if err != nil {
		pkg.Error("失败", zap.Error(err))
		return nil, err
	}
	var CollList []*user.CollectList
	for _, cl := range list {
		CollList = append(CollList, &user.CollectList{
			GoodId: int64(cl.GoodId),
			SkuId:  int64(cl.SkuId),
			Price:  float32(cl.Price),
			Num:    int64(cl.Num),
		})
	}

	return &user.CollectListResponse{
		List: CollList,
	}, nil
}
